﻿using UnityEngine;
using System.Collections;

public class Missile : MonoBehaviour {

	public float speed;//移动速度
	public float power = 5f;//伤害值
	public Player target;//玩家目标

	private bool running=false;//是否启动
	
	void Start () {
		Destroy (gameObject, 5f);
	}
	
	
	void Update () {
		if (!running)
			return;
		if (target == null)
			return;
		Vector3 dir = (target.transform.position - this.transform.position).normalized;
		transform.rotation = Quaternion.FromToRotation(Vector3.left, dir);
		transform.position += speed * Time.deltaTime * dir;
	}

    //发射
	public void Launch()
	{
		running = true;
	}
}
